package com.gzk.oeno.business.vin;

import java.util.Date;

import org.apache.commons.lang.StringUtils;

import com.gzk.oeno.business.IFriendlyNamed;
import com.gzk.oeno.tech.ui.Formator;
import com.gzk.utils.data.IdObject;

public class Prix implements IdObject<Integer>, IFriendlyNamed{

	private Integer id;
	private Vin vin;
	private Date date;
	private String devise;
	private Float prix;
	private String vendeur;
	
	public Prix(){}
	
	public void setDate(Date date) {
		this.date = date;
	}

	public void setDevise(String devise) {
		this.devise = devise;
	}

	public void setPrix(Float prix) {
		this.prix = prix;
	}

	public void setVendeur(String vendeur) {
		this.vendeur = vendeur;
	}

	public Date getDate() {
		return date;
	}

	public String getDevise() {
		return devise;
	}

	public Float getPrix() {
		return prix;
	}

	public String getVendeur() {
		return vendeur;
	}

	@Override
	public Integer getId() {
		return id;
	}

	@Override
	public void setId(Integer id) {
		this.id = id;
	}

	public Vin getVin() {
		return vin;
	}

	public void setVin(Vin vin) {
		this.vin = vin;
	}

	@Override
	public String getFriendlyName() {
		StringBuilder sb = new StringBuilder(Formator.getFormCurrencyFormat().format(getPrix()));
		sb	.append(" ").append(getDevise())
			.append(" (le ").append(Formator.getDateFormat().format(getDate()));
		if (StringUtils.isNotEmpty(getVendeur())){
			sb.append(" chez ").append(getVendeur());
		}
		sb.append(")");
		return sb.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Prix other = (Prix) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

}
